﻿using System.ComponentModel.DataAnnotations.Schema;

namespace project1.Models
{
    public class Order
    {
        public string Orderid { get; set; }

        public string Customerid { get; set; }

        [ForeignKey("Customerid")]

        public Customer? oneCustomer { get; set; }

        public string oneCustomerName { get => (oneCustomer != null) ? oneCustomer.name : ""; }

        public DateTime CreateTime { get; set; }

        public List<OrderDetail> Details { get; set; }

        public Order()
        {
            Orderid = Guid.NewGuid().ToString();
            Details = new List<OrderDetail>();
            CreateTime = DateTime.Now;
        }

        public Order(string orderid,Customer customer,List<OrderDetail> items)
        {
            Orderid = orderid;
            this.oneCustomer = customer;
            this.Details = items;
        }

        public double TotalPrice
        {
            get => Details.Sum(item => item.totalPriceofthis);

        }

        public void AddDetail(OrderDetail orderitem)
        {
            Details.Add(orderitem);
        }













    }
}
